package tmhprediction.main;

import tmhprediction.classification.TMHClassifier;
import tmhprediction.eval.TMHJury1;
import weka.core.Instances;

/***
 * creates three SVMs and averages their results (jury-decision)
 * @author steckl
 */
public class TMHSVM1 {
	
	// result after jury-decision
	private TMHResultMap juriedResult = null;
	
	/**
	 * trainiert 3 svms mit den models, testet den test-set und macht eine jury-decision
	 * @param model0
	 * @param model1
	 * @param model2
	 * @param testInstances
	 * @param cacheSize the cache-size used in libSVM
	 * @param svmLevel just for naming logfiles
	 * @throws Exception
	 */
	public TMHSVM1(String model0, String model1, String model2, Instances testInstances, String svmLevel, double cutOff0, double cutOff1, double cutOff2) throws Exception {
		this(model0,model1,model2,testInstances,svmLevel,cutOff0, cutOff1, cutOff2, 40);
	}
		
	/**
	 * trainiert 3 svms mit den models, testet den test-set und macht eine jury-decision
	 * @param model0
	 * @param model1
	 * @param model2
	 * @param testInstances
	 * @param svmLevel just for naming logfiles
	 * @throws Exception
	 */
	public TMHSVM1(String model0, String model1, String model2, Instances testInstances, String svmLevel, double cutOff0, double cutOff1, double cutOff2, double cacheSize) throws Exception {
		
		TMHClassifier svm = new TMHClassifier(model0, testInstances,cacheSize);
		TMHProgram2.logTime("svm "+svmLevel+" model0 geladen");
		TMHResultMap resMap0 = svm.createResultMap();
		TMHProgram2.logTime("svm "+svmLevel+" resultmap0 generiert");
//		TMHProgram2.doStatistics("svm"+svmLevel+"_resmap0",resMap0);
		
		System.gc();
		
		svm = new TMHClassifier(model1, testInstances,cacheSize);
		TMHProgram2.logTime("svm "+svmLevel+" model1 geladen");
		TMHResultMap resMap1 = svm.createResultMap();
		TMHProgram2.logTime("svm "+svmLevel+" resultmap1 generiert");
//		TMHProgram2.doStatistics("svm"+svmLevel+"_resmap1",resMap1);
		
		System.gc();
		
		svm = new TMHClassifier(model2, testInstances,cacheSize);
		TMHProgram2.logTime("svm "+svmLevel+" model2 geladen");
		TMHResultMap resMap2 = svm.createResultMap();
		TMHProgram2.logTime("svm "+svmLevel+" resultmap2 generiert");
//		TMHProgram2.doStatistics("svm"+svmLevel+"_resmap2",resMap2);
		
		System.gc();

		juriedResult = TMHJury1.makeJuryDecision(resMap0, resMap1, resMap2, cutOff0, cutOff1, cutOff2);
		TMHProgram2.logTime("jury of level 1 has decided");
	}
	
	/***
	 * get the result map after jury decision
	 * @return
	 */
	public TMHResultMap getJuryResult() {
		return juriedResult;
	}
}
